<?php
/**
 * ClassName: HospitalService
 * Description:
 * @Author 周昌
 * @Create 2023/11/8 14:00
 */

namespace service\admin;


use epii\cache\Cache;
use service\BaseService;

class HospitalService extends BaseService
{
    public static $hospital_type=[0=>'总院',1=>'分院',2=>'加盟院',3=>'加盟分院'];
    public static $hospital_type_index=['general'=>0,'branch'=>1,'franchise_general'=>2,'franchise_branch'=>3];
    protected static $model='model\HospitalModel';
    public static $qrcode_url='https://www.chengyizang.cn/sign?hospital_id=';//签到二维码跳转路径
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * #User: Administrator
     * #Time: 2023/11/8 14:08
     * #Author:周昌
     * #Description:
     * @return array
     */
    public static function hospitalTypeSelect()
    {
        static $hospital_type_select=[];
        if(empty($hospital_type_select)){
            foreach (self::$hospital_type as $k=>$v){
                    $row=[];
                    $row['id']=$k;
                    $row['name']=$v;
                    $hospital_type_select[]=$row;
            }
            array_unshift($hospital_type_select,['id'=>'','name'=>'-----请选择-----']);
        }
        return $hospital_type_select;
    }
    //根据hospital_id 获取医院分组id
    public static function getGroupId($hospital_id)
    {
        $info=self::$model::getInfo(['id'=>$hospital_id],'id,pid');
        return $info['pid']?:$info['id'];
    }
    //获取医院组下全部医院列表数据
    public static function getGroupList($hospital_id)
    {
        $hospital_group_id=self::getGroupId($hospital_id);
        $where=[
            ['id','=',$hospital_group_id],
            ['pid','=',$hospital_group_id],
        ];
        $res=self::$model::getListWhereOr($where,'id,name');
        return $res;
    }
    //列表数据
    public static function getAjaxData($where)
    {
        $table = self::$model::order('id desc');
        return self::tableJsonData($table, $where, function ($data){
            $data['type_name'] = self::$hospital_type[$data['type']];
            $data['parent_name'] = $data['pid']?self::getNameByKey($data['pid'],['pid'=>0]):'';
            return $data;
        });
    }

}